<template>
    <div class="entry">
        <!-- 左侧菜单栏 -->
        <template>
            <EntryLeftModule
                :dataSource="fileSourceCategoryData"
                :clauseSourceCode="clauseQueryParam.clauseSourceCode"
                :currentNodekey="'1'"
                @emitIconEdit="emitIconEdit"
                @emitIconEditOutline="emitIconEditOutline"
                @emitIconPlus="emitIconPlus"
                @emitIconTime="emitIconTime"
                @emitIconDelete="emitIconDelete"
                @handleNodeClick="handleNodeClick"
            >
                <template slot="title">
                    <HeaderTitle>
                        <div slot="title">{{treeNodeData.level == '1'?'条目标准库':(treeNodeData.indexType == '1'? '外规类指标库' : '产品类指标库')}}</div>
                    </HeaderTitle>
                </template>
                <template slot="treeIcon">
                    <i class="el-icon-office-building" style="color:#3498ff !important;"></i>
                </template>
            </EntryLeftModule>    
        </template>
        <!-- 右侧内容框 -->
        <template>
            <div class="content">
                <!-- 合规条款 -->
                <div class="content-top">
                    <HeaderTitle>
                        <div slot="title">合规条款</div>
                    </HeaderTitle>
                    <div class="operate">
                        <div class="operate-btn">
                            <div class="leftBtn">
                                <el-button type="primary" :disabled="(treeNodeData !=''&&treeNodeData.level==4?false:true)" @click="handleClauseBtn(treeNodeData.indexType == '1'?'外规新增':'产品新增')">新增</el-button>
                                <el-button type="danger" @click="delClauseDialog(clauseCodes, '批量删除')">批量删除</el-button>
                                <el-button v-if="treeNodeData.indexType == 1" :disabled="treeNodeData.id == '1'" :key="treeNodeData.id" @click="handleClauseBtn('复制')">迁移复制</el-button>
                                <el-button v-else-if="treeNodeData.indexType == 2" :disabled="treeNodeData.level != 4" @click="handleProductClauseBtn('复制')">产品条款复制</el-button>
                                <el-button type="primary" @click="enableClause('启用')">启用</el-button>
                                <el-button type="danger" @click="enableClause('停用')">停用</el-button>
                            </div>
                            <div class="rightBtn">
                                <el-input 
                                    size="small"
                                    v-model="clauseQueryParam.clauseTextLike"
                                    prefix-icon="el-icon-search" 
                                    placeholder="请输入条款原文" 
                                    style="width:230px;margin-right:10px" 
                                    @input="clauseTextLikeQuery"
                                />

                                <el-button-group>
                                    <el-button @click="clauseAdvancedQuery">高级查询</el-button>
                                    <el-button icon="el-icon-refresh-right" @click="getIndexClauseListRefresh"></el-button>
                                    <el-button icon="el-icon-upload2" @click="downLoadGroupFileBtn"></el-button>
                                    <el-button icon="el-icon-setting" @click="layoutDialog = true"></el-button>
                                </el-button-group>
                            </div>
                        </div>
                        <div style="width: 98%; height:100%; margin: 0 auto; border: 1px solid #d7d7d7;">
                            <vxe-table
                                ref="upstreamTable"
                                :key="tableKey"
                                :data="indexClauseList"
                                border
                                stripe
                                resizable
                                :resizable-config="{ minWidth: '50' }"
                                show-header-overflow="tooltip"
                                size="mini"
                                style="width: 100%"
                                max-height="270px"
                                header-align="center"
                                show-overflow
                                @checkbox-change="clauseChangeEvent"
                                @checkbox-all="clauseChangeEvent"
                                @cell-click="handleRow"
                                :cell-style="cellStyle"
                                auto-resize
                            >
                                <vxe-column type="checkbox" width="50" fixed="left" align="center"></vxe-column>
                                <vxe-column
                                    v-for="(item) in showFieldList"
                                    :key="item.clauseNo"
                                    :field="item.id"
                                    :fixed="item.fixed"
                                    :title="item.content"
                                    :sortable="item.sortable"
                                    :width="item.width || 120"
                                    :filters="item.filters"
                                    :filter-method="filterHandler"
                                >
                                    <template #filter="{ $panel, column }" v-if="['clauseText', 'indexSourceName', 'executiveStandard'].includes(item.id)">
                                        <el-input
                                            class="my-input"
                                            type="type"
                                            v-for="(option, index) in column.filters"
                                            :key="index"
                                            v-model="option.data"
                                            @input="$panel.changeOption($event, !!option.data, option)"
                                        />
                                    </template>
                                    <template slot-scope="scope">
                                        <span v-if="['clauseCode'].includes(item.id)">
                                            <span v-if="scope.row.modifyEvent === '2'" style="padding-right:3px">
                                                <i class="el-icon-setting" />
                                            </span>
                                            <span v-else-if="scope.row.modifyEvent === '3'" style="padding-right:3px">
                                                <i class="el-icon-delete" />
                                            </span>
                                            <span v-else-if="scope.row.modifyEvent === '1'" style="padding-right:3px">
                                                <i class="el-icon-folder-add" />
                                            </span>
                                            <span>{{scope.row.clauseCode}}</span>
                                        </span>
                                        <span v-else-if="['clauseStatus'].includes(item.id)">
                                            <span style="color:green" v-if="scope.row.clauseStatus == true">启用</span>
                                            <span style="color:red" v-else-if="scope.row.clauseStatus == false">禁用</span>
                                        </span>
                                        <span v-else-if="['passiveTransfinite'].includes(item.id)">{{scope.row.passiveTransfinite == true ? '是' : '否'}}</span>
                                        <span v-else-if="['realTimeSupport'].includes(item.id)">{{scope.row.realTimeSupport == 1 ? '支持' : (scope.row.realTimeSupport == 2 ? '部分支持' : (scope.row.realTimeSupport == 3 ? '不支持' :''))}}</span>
                                        <span v-else-if="['hdSupport'].includes(item.id)">{{scope.row.hdSupport == 1 ? '支持' : (scope.row.hdSupport == 2 ? '部分支持' : (scope.row.hdSupport == 3 ? '不支持' :''))}}</span>
                                        <span v-else-if="['modifyDate'].includes(item.id)">{{dateFormat(scope.row.modifyDate)}} {{timeFormat(scope.row['modifyTime']) || '--'}}</span>
                                        <span v-else-if="['createUserName'].includes(item.id)">
                                            <span v-if="scope.row.modifyEvent == '1'">{{scope.row.createUserName}}</span>
                                            <span v-else>{{scope.row.modifyUser}}</span>
                                        </span>
                                        <span v-else>{{scope.row[item.id]}}</span>
                                    </template>
                                </vxe-column>
                                <vxe-column title="操作" width="240" fixed="right">
                                    <template slot-scope="scope">
                                        <RiskIconButton
                                            type="primary"
                                            icon="el-icon-edit"
                                            topTitle="修改"
                                            v-authCode="B_0188"
                                            :disabled="scope.row.modifyEvent? true : false"
                                            @on-click="openhandleClauseDialog(scope.row, scope.row.indexType == '1'?'外规修改':'产品修改')"
                                        ></RiskIconButton>
                                        <RiskIconButton
                                            type="danger"
                                            icon="el-icon-delete"
                                            topTitle="删除"
                                            v-authCode="B_0191"
                                            :disabled="scope.row.modifyEvent? true : false"
                                            @on-click="delClauseDialog(scope.row, '单个删除')"
                                        ></RiskIconButton>
                                        <RiskIconButton
                                            type="primary"
                                            icon="el-icon-view"
                                            topTitle="查看"
                                            v-authCode="B_0191"
                                            :disabled="scope.row.modifyEvent? true : false"
                                            @on-click="openhandleClauseDialog(scope.row, scope.row.indexType == '1'?'外规查看':'产品查看')"
                                        ></RiskIconButton>
                                        <RiskIconButton
                                            type="primary"
                                            icon="el-icon-time"
                                            topTitle="记录"
                                            v-authCode="B_0191"
                                            :disabled="scope.row.modifyEvent? true : false"
                                            @on-click="openClauseRecordDialog(scope.row)"
                                        ></RiskIconButton>
                                    </template>
                                </vxe-column>
                            </vxe-table>
                            <div class="block">
                                <risk-pagination :paging="groupPage" @page-change="pageRet"></risk-pagination>
                            </div> 
                        </div>
                    </div>
                </div>
                <!-- 合规规则 -->
                <div class="content-bottom">
                    <HeaderTitle>
                        <div slot="title">合规规则</div>
                    </HeaderTitle>
                    <ComplianceRules
                        :treeNodeData="treeNodeData"
                        :indexClauseRelation="indexClauseRelation"
                        :clauseCodesList="clauseCodesList"
                        :indexClauseList="indexClauseList"
                        :checkItemIs="checkItemIs"
                    ></ComplianceRules>
                </div>
            </div>    
        </template>
        <!-- 子组件类弹窗 -->
        <template>
            <!-- 新增来源文件弹窗 -->
            <SourceDocumentDialog
                :addSourceDialog="addSourceDialog"
                :indexItem="indexItem"
                :indexClauseList="indexClauseList"
                @emitSource="emitSource"
                @emitAddSourceDialog="emitAddSourceDialog"
                @emitAddFileSourceCategoryNode="getFileSourceCategoryData"
            ></SourceDocumentDialog>
            <!-- 合规条款新增弹窗 -->
            <TreatyArticleDialog
                :addTreatyDialog="addTreatyDialog"
                :sourceSettteingType="sourceSettteingType"
                :treeNodeData="treeNodeData"
                :clauseCodeItem="clauseCodeItem"
                :clauseCodes="clauseCodes"
                @emitTreatyArticle="emitTreatyArticle"
            ></TreatyArticleDialog>
            <!-- 系列条款弹窗 -->
            <SerialClauseDialog
                :serialClauseDialog="serialClauseDialog"
                :treeNodeData="treeNodeData"
                @emitSerialClauseDialog="emitSerialClauseDialog"
            ></SerialClauseDialog>
            <!-- 条款高级查询 -->
            <ClauseQueryDialog
                :clauseQueryDialog="clauseQueryDialog"
                :treeNodeData="treeNodeData"
                :clauseQueryParam="clauseQueryParam"
                @emitClauseQuery="emitClauseQuery"
            ></ClauseQueryDialog>
            <!-- 条目设置 -->
            <!-- <ItemSettingDialog></ItemSettingDialog> -->
            <!-- 条目记录弹窗 -->
            <EntryRecordDialog
                :entryRecordDialog="entryRecordDialog"
                :entryRecordItem="entryRecordItem"
                @emitEntryRecordDialog="emitEntryRecordDialog"
            ></EntryRecordDialog>
            <!-- 条款记录弹窗     -->
            <ClauseRecordDialog
                v-show="clauseRecordDialog"
                :clauseRecordDialog="clauseRecordDialog"
                :clauseRecordItem="clauseRecordItem"
                @emitClauseRecordDialog="emitClauseRecordDialog"
            ></ClauseRecordDialog>
            <!-- 树节点新增、编辑 -->
            <CategoryNodeDialog
                :categoryNodeDialog="categoryNodeDialog"
                :categoryNodeType="categoryNodeType"
                :indexItem="indexItem"
                @emitCategoryNodeDialog="emitCategoryNodeDialog"
            ></CategoryNodeDialog>
            <!-- 删除确认窗口 -->
            <DeletionConfirmationDialog
                title="警告"
                :delConfirmationDialog="delConfirmationDialog"
                @emitDialogVisible="emitDialogVisible"
                @emitHandleBtn="emitHandleBtn"
            >
                <div slot="content1">{{delContent}}</div>
            </DeletionConfirmationDialog>
            <!-- 布局设置 -->
            <RiskTableLayout
                title="页面布局"
                :visible.sync="layoutDialog"
                :field-list="tableColumns"
                :selected-field-list="selectedFieldList"
                :fixed-field-list="fixedFieldList"
                table-name="ENTRY_STANDARD_LIBRARY_CLAUSE"
                @on-submit="onSubmit"
            />
        </template>
    </div>
</template>
<script lang="ts">
import { Component, Vue, Watch } from 'vue-property-decorator';
import EntryLeftModule from './entry-left-module.vue';
import RiskIconButton from '@/common/components/risk-icon-button.vue';
import SourceDocumentDialog from './components/source-document-dialog.vue';
import HeaderTitle from './commom/header-title.vue';
import RiskPagination from '@/common/components/risk-pagination.vue';
import TreatyArticleDialog from './components/treaty-article-dialog.vue';
import SerialClauseDialog from './components/serial-clause-dialog.vue';
import ClauseQueryDialog from './components/clause-query-dialog.vue';
import RiskTableLayout from '@/common/components/risk-table-layout.vue';
import EntryRecordDialog from './components/entry-record-dialog.vue'
import ClauseRecordDialog from './components/clause-record-dialog.vue'
import CategoryNodeDialog from './components/category-node-dialog.vue'
import ComplianceRules from './compliance-rules.vue'
import DeletionConfirmationDialog from './commom/deletion-confirmation-dialog.vue'
import { dateFormat, timeFormat } from '@/utils/tools';
import { getTableLayout } from '@/common/api/commonApi';
import Invest from '@/common/dict/invest';
import { downLoadFile } from '@/utils/request';
export interface pages {
    total?: number;
    pageSize?: number;
    currentPage?: number;
}

@Component({
    name: 'ComplianceClause',
    components: {
        EntryLeftModule,
        RiskIconButton,
        SourceDocumentDialog,
        HeaderTitle,
        RiskPagination,
        TreatyArticleDialog,
        SerialClauseDialog,
        ClauseQueryDialog,
        RiskTableLayout,
        EntryRecordDialog,
        ClauseRecordDialog,
        CategoryNodeDialog,
        ComplianceRules,
        DeletionConfirmationDialog
    },
})
export default class ComplianceClause extends Vue {
    Invest: any = new Invest();
    dateFormat = dateFormat;
    timeFormat = timeFormat;
    fileSourceCategoryData = []; // 文件来源分类数据
    indexClauseList = []; // 条款列表数据
    addSourceDialog: boolean = false; // 新增来源文件弹窗
    addTreatyDialog: boolean = false; // 新增合规条款弹窗
    clauseQueryDialog: boolean = false; // 条款高级查询弹窗
    clauseRecordDialog: boolean = false; // 条款记录弹窗
    entryRecordDialog: boolean = false; // 条目记录弹窗
    categoryNodeDialog: boolean = false;
    serialClauseDialog: boolean = false; // 系列条款弹窗
    sourceSettteingType: string = ''; // 条款设置弹窗类型
    delConfirmationDialog: boolean = false;
    delContent: string = '是否删除所选记录？';
    treeNodeData = ''; // 当前选择树节点数据
    clauseCodeItem = {
        clauseCode: '',
        indexSourceCode: ''
    }; // 条款操作行clauseCode
    clauseCodes = []; // 条款多选code
    clauseCodesList = []; // 条款多选全部数据
    clauseRecordItem = ''; // 条款操作记录clauseCode
    entryRecordItem = ''; // 条目操作记录节点
    indexItem = ''; // 指标操作行数据
    categoryNodeType = ''; // 节点新增、编辑
    clauseRow: string = ''; // 条款table行code
    delType = {
        type: '',
        content: ''
    }; // 删除类型
    clauseQueryParam = { // 列表查询条件
        belongFund: '',
        clauseCode: '',
        clauseNo: '',
        clauseSourceCode: '1',
        clauseStatus: '',
        clauseText: '',
        clauseTextLike: '',
        clauseType: '',
        hdSupport: '',
        paging: {
            currentPage: 1,
            pageSize: 50
        },
        passiveTransfinite: null,
        realTimeSupport: '',
        status: '',
        suitableFund: '',
        versionNumber: '',
        versionValid: ''
    }
    indexClauseRelation = {
        clauseCode: '',
        modifyEvent: ''
    }
    // 全部表格列
    tableColumns: any[] = [
        { content: '序号', id: 'clauseCode', sortable: true, fixed: 'left' },
        { content: '版本号', id: 'versionNumber', sortable: true },
        { content: '来源名称', id: 'indexSourceName', sortable: false, filters: [{ data: '' }], },
        { content: '条款原文', id: 'clauseText', sortable: false, filters: [{ data: '' }] },
        { content: '执行标准', id: 'executiveStandard', sortable: false },
        { content: '托管行意见', id: 'depositOpinions', sortable: false },
        { content: '行业调研', id: 'industryResearch', sortable: false },
        { content: '条款号', id: 'clauseNo', sortable: false },
        { content: '条款状态', id: 'clauseStatus', sortable: false },
        { content: '是否可被动超限', id: 'passiveTransfinite', sortable: false },
        { content: '条款适用产品', id: 'suitableFundType', sortable: false },
        { content: '实时系统支持情况', id: 'realTimeSupport', sortable: false, width: 180 },
        { content: '恒生系统支持情况', id: 'hdSupport', sortable: false, width: 180 },
        { content: '修改日期', id: 'modifyDate', sortable: true, width: 180 },
        { content: '修改人', id: 'modifyUser', sortable: false },
    ];
    private groupPage: pages = {
        currentPage: 1,
        pageSize: 50,
        total: 0,
    };
    timeout = null; // 防抖
    layoutDialog: boolean = false; // 布局显示值
    showFieldList: any[] = []; // 要显示的表格列
    // 已选择字段列表
    selectedFieldList: any[] = [];
    fixedFieldList: any[] = [
        { content: '序号', id: 'clauseCode', sortable: true },
        { content: '条款原文', id: 'clauseText', sortable: false, filters: [{ data: '' }] },
    ];
    iconDom: any = null;
    tableKey: number = 0;
    calcLoading: boolean = false;
    checkItemIs: boolean = false; // 是否存在为复核条款
    // entryTypeArr: any[] = []; // 风险类型

    created() {
        this.getFileSourceCategoryData();
    }
    mounted() {
        this.queryLayout();
    }
    // 当前选择树节点数据
    handleNodeClick(param1, param2) {
        this.treeNodeData = param1;
        this.clauseQueryParam.clauseSourceCode = param1.id;
        this.checkItemIs = false;
        this.getIndexClauseList();
    }
    // 获取文件来源分类数据
    getFileSourceCategoryData() {
       this.$axios.post('/indexSource/fileSourceCategoryData', {sourceName: ''}).then((res: any) => {
            if (res) {
                this.fileSourceCategoryData = [];
                this.clauseQueryParam.clauseSourceCode = res[0].id;
                this.fileSourceCategoryData.push(res[0]);
                this.treeNodeData = res[0];
                this.getIndexClauseList();    
            }
        }); 
    }
    // 条款列表查询
    getIndexClauseList() {
       this.$axios.post('/indexClause/list', this.clauseQueryParam).then((res: any) => {
            if (res) {
                this.clauseQueryDialog = false;
                this.indexClauseList = [];
                this.clauseCodes = [];
                res.list.forEach(item => this.indexClauseList.push(item))
                this.groupPage.total = res.total;
                if (res.list.length != 0) {
                    this.indexClauseRelation.clauseCode = res.list[0].clauseCode;
                    this.indexClauseRelation.modifyEvent = res.list[0].modifyEvent || '';
                } else {
                    this.indexClauseRelation.clauseCode = '';
                    this.indexClauseRelation.modifyEvent = ''
                }
            }    
        }); 
    }
    // 刷新数据
    getIndexClauseListRefresh() {
        this.getIndexClauseList();
    }
    // 条款btn---新增、复制
    handleClauseBtn(type) {
        if (type == '复制' && this.clauseCodes.length == 0) {
            this.yh_message_warn('选择条款不可为空！');
            return
        }
        if (type == '复制' && this.checkItemIs == true) {
            this.yh_message_warn('存在未复核条款！');
            return
        }
        if (this.clauseCodes.length == 1 && type == '复制') {
            this.sourceSettteingType = '外规单个复制';
        } else if (this.clauseCodes.length > 1 && type == '复制') {
            this.sourceSettteingType = '外规多个复制';
        } else {
            this.sourceSettteingType = type;
        }
        this.addTreatyDialog = true;
    }
    // 产品条款复制btn
    handleProductClauseBtn() {
        if (this.checkItemIs == true) {
            this.yh_message_warn('存在未复核条款！');
            return
        }
        this.serialClauseDialog = true;
    }
    delClauseDialog(clauseCodes, param2) {
        if (this.clauseCodes.length == 0 && param2 == '批量删除') {
            this.yh_message_warn('选择条款不可为空！');
            return
        } 
        if (this.checkItemIs == true && param2 == '批量删除') {
            this.yh_message_warn('存在未复核条款！');
            return
        }
        this.delConfirmationDialog = true;
        this.delContent = '是否删除所选记录？';
        this.delType.type = param2;
        if (param2 == '单个删除') {
            this.delType.content = clauseCodes.clauseCode;
        } else {
            this.delType.content = '';
        }
    }
    // 条款删除
    delClause() {
        let data = []
        if (this.delType.type == '批量删除') {
            data = this.clauseCodes;
        } else if (this.delType.type == '单个删除') {
            data.push(this.delType.content)
        }
        this.$axios.post('/indexClause/delete', data).then((res: any) => {
            if (res) {
                this.delConfirmationDialog = false;
                this.yh_message_success('删除成功！');
                this.clauseQueryParam.paging.currentPage = 1;
                this.clauseQueryParam.paging.pageSize = 50;
                this.getIndexClauseList();
            }
        }).catch(() => {
            this.delConfirmationDialog = false;
        }); 
    }
    // 启用、停用条款
    enableClause(type) {
        if (this.clauseCodes.length == 0) {
            this.yh_message_warn('选择条款不可为空！');
            return
        }
        if (type == '启用') {
            this.$axios.post('/indexClause/enable', this.clauseCodes).then((res: any) => {
                if (res) {
                    this.clauseCodes = [];
                    this.yh_message_success('启用成功！');
                    this.getIndexClauseList();
                }
            }); 
        } else if (type == '停用') {
            this.$axios.post('/indexClause/forbid', this.clauseCodes).then((res: any) => {
                if (res) {
                    this.clauseCodes = [];
                    this.yh_message_success('禁用成功！');
                    this.getIndexClauseList();
                }
            }); 
        }
    }
    // 条款原文模糊搜索
    clauseTextLikeQuery(param) {
        this.debounce(this.getIndexClauseList, 500)
    }
    // 条款高级查询btn
    clauseAdvancedQuery() {
        this.clauseQueryDialog = true;
    }
    // 导出
    downLoadGroupFileBtn() {
        if (this.indexClauseList.length == 0) {
            this.yh_message_warn('当前数据为空!');
            return
        }
        if (this.clauseCodes.length > 0) {
            downLoadFile({
                url: '/indexClause/export',
                method: 'post',
                data: {
                    ...this.clauseQueryParam,
                    includeClauseCodes: this.clauseCodes
                },
            });
        } else if (this.clauseCodes.length == 0) {
            downLoadFile({
                url: '/indexClause/export',
                method: 'post',
                data: {
                    ...this.clauseQueryParam,
                    includeClauseCodes: []
                },
            });
        }
        // downLoadFile({
        //     url: '/indexClause/export',
        //     method: 'post',
        //     data: this.clauseQueryParam,
        // });
    }
    // 条款多选
    clauseChangeEvent(checked, row, rowIndex) {
        this.clauseCodes = [];
        this.clauseCodesList = [];
        this.checkItemIs = false;
        if (checked.selection.length != 0) {
            for (let i = 0; i < checked.selection.length; i++) {
                this.clauseCodes.push(checked.selection[i].clauseCode);
                this.clauseCodesList.push(checked.selection[i]);
            }  
            for (let i = 0; i < checked.selection.length; i++) {
                if (checked.selection[i].modifyEvent) {
                    this.checkItemIs = true;
                    return
                }
            }  
        } else {
            this.checkItemIs = false;
        }
    }
    // 编辑条款
    openhandleClauseDialog(scope, type) {
        this.addTreatyDialog = true;
        this.sourceSettteingType = type;
        // this.clauseCodeItem = scope;
        this.clauseCodeItem.clauseCode = scope.clauseCode
        this.clauseCodeItem.indexSourceCode = scope.indexSourceCode;
    }
    // 删除条款
    handleClauseRemove(param1, param2) {
        if (param2 == '单个删除') {

        }
    }
    // 条款操作记录btn
    openClauseRecordDialog(scope) {
        this.$nextTick(() => {
            this.clauseRecordDialog = true;
            this.clauseRecordItem = scope.clauseCode;
        })
    }
    // 单击合规条款table行
    handleRow(row, event, column) {
        this.indexClauseRelation.clauseCode = row.row.clauseCode;
        this.indexClauseRelation.modifyEvent = row.row.modifyEvent;
    }
    // 新增来源文件弹窗 emit
    emitAddSourceDialog(param) {
        this.addSourceDialog = param
    }
    // 合约条款新增弹窗emit
    emitTreatyArticle(param1, param2) {
        this.addTreatyDialog = param1;
        if (param2 == 'query') {
            this.clauseQueryParam.paging.currentPage = 1;
            this.clauseQueryParam.paging.pageSize = 50;
            this.getIndexClauseList();
        }
    }
    // 左侧菜单节点名称编辑
    emitIconEdit(param) {
        this.indexItem = param;
        this.categoryNodeDialog = true;
        this.categoryNodeType = '修改';
    }
    // 左侧菜单条目节点编辑emit
    emitIconEditOutline(param) {
        this.indexItem = param;
        this.addSourceDialog = true;
    }
    // 左侧菜单条目节点添加emit
    emitIconPlus(param) {
        if (param.label == '外规类指标') {
            this.categoryNodeDialog = true;
            this.categoryNodeType = '新增';
            this.indexItem = param;
        } else {
            this.indexItem = param;
            this.addSourceDialog = true;
        }
    }
    // 左侧菜单条目节点删除emit
    emitIconDelete(param) {
        console.log(param, 'deleteParam');
        this.entryRecordItem = param;
        this.delType.type = '来源删除';
        this.delContent = `是否删除来源:${this.entryRecordItem['label']}？`;
        this.delConfirmationDialog = true;
    }
    // 获取指标来源操作日志
    emitIconTime(param) {
        this.entryRecordItem = param;
        this.entryRecordDialog = true;
    }
    // 条目记录弹窗emit
    emitEntryRecordDialog(param) {
        this.entryRecordDialog = param;
    }
    // 新增来源文件弹窗emit
    emitSource(param) {
        this.addSourceDialog = param;
    }
    // 高级查询弹窗emit
    emitClauseQuery(param1, param2) {
        if (param2 == '') {
            this.clauseQueryDialog = param1;
        } else if (param2 != '') {
            this.clauseQueryParam.clauseCode = param2.clauseCode; // 条款序号
            this.clauseQueryParam.clauseStatus = param2.clauseStatus; // 条款状态
            this.clauseQueryParam.clauseText = param2.clauseText; // 条款原文
            this.clauseQueryParam.versionNumber = param2.versionNumber; // 版本号
            this.clauseQueryParam.clauseNo = param2.clauseNo; // 条款号
            this.clauseQueryParam.versionValid = param2.versionValid; // 版本是否有效
            this.clauseQueryParam.suitableFund = param2.suitableFund; // 条款适用产品
            this.clauseQueryParam.passiveTransfinite = param2.passiveTransfinite; // 是否可被动超限
            this.clauseQueryParam.realTimeSupport = param2.realTimeSupport; // 风控系统是否支持
            this.clauseQueryParam.hdSupport = param2.hdSupport; // 恒生系统能否支持
            this.getIndexClauseList();
        }
    }
    // 条款操作记录
    emitClauseRecordDialog(param) {
        this.clauseRecordDialog = param;
    }
    // 来源名称节点新增、编辑
    emitCategoryNodeDialog(param1, param2) {
        this.categoryNodeDialog = param1;
        if (param2 == '刷新接口') {
            this.getFileSourceCategoryData()
        }
    }
    // 系列条款弹窗额emit
    emitSerialClauseDialog(param) {
        this.serialClauseDialog = param;
    } 
    // 删除确认窗口显示
    emitDialogVisible(param) {
        this.delConfirmationDialog = param;
    }
    // 删除确认窗口
    emitHandleBtn() {
        if (['批量删除', '单个删除'].includes(this.delType.type)) {
            this.delClause();
        } else if (this.delType.type == '来源删除') {
            this.$axios.post('/indexSource/deleteFileSourceCategoryNode', {id: this.entryRecordItem['id']}).then((res: any) => {
                    this.delConfirmationDialog = false;
                    this.yh_message_success('删除成功！');
                    this.getFileSourceCategoryData();
            }).catch(() => {
                this.delConfirmationDialog = false;
            }); 
        }
    }
    // 分页
    private pageRet(): void {
        this.clauseQueryParam.paging.currentPage = this.groupPage.currentPage;
        this.clauseQueryParam.paging.pageSize = this.groupPage.pageSize;
        this.getIndexClauseList();
    }
    filterChangeEvent() {}
    // 防抖
    debounce(fun, time = 500) {
        if (this.timeout) {
            clearTimeout(this.timeout)
        }
        this.timeout = setTimeout(() => {
            fun()
        }, time);
    }
    // 条款点击行单元格样式
    cellStyle({ row, column, rowIndex, columnIndex }) {
        if (row.clauseCode == this.indexClauseRelation.clauseCode) {
            return {background: '#e6f7ff'}
        }
    }
    /**
     * 提交成功后回调
     * @param {Object} 回调数据
     */
    async onSubmit(data) {
        await this.queryLayout();
    }
        /* **************************** 布局设置start ***************************** */
    // 获取页面布局信息
    async queryLayout() {
        this.calcLoading = true;
        const resList: any = await new Promise((resolve, reject) => {
            getTableLayout('ENTRY_STANDARD_LIBRARY_CLAUSE')
                .then((res: any) => {
                    resolve(res);
                })
                .catch(err => {
                    reject(err);
                });
        });
        if (resList) {
            this.selectedFieldList = JSON.parse(resList);
            this.showFieldList = this.fixedFieldList.concat(this.selectedFieldList);
            this.calcLoading = false;
        } else {
            this.showFieldList = this.tableColumns;
            this.selectedFieldList = this.tableColumns;
            this.calcLoading = false;
        }
        // 重新渲染表格
        this.tableKey++;
        this.changeTable();
    }
    changeTable() {
        const _this = this;
        this.$nextTick(() => {
            let iconDom = (_this.$refs['upstreamTable'] as any).$el.querySelectorAll('.vxe-icon--funnel');
            for (let i:any = 0; i < iconDom.length; i++) {
                if (['来源名称', '条款原文'].includes(iconDom[i].parentNode.parentNode.children[0].innerHTML)) {
                    iconDom[i].className = 'vxe-filter--btn el-icon-search';
                }
            }
        });
    }
    // 转表格筛选下拉框数据
    objToArr(param) {
        const list = [];
        for (const key in param) {
            list.push({ label: param[key], value: key });
        }
        return list;
    }
    // 表格列筛选数据
    filterHandler({ option, row, column }) {
        const property = column['property'];
        return row[property].includes(option.data);
    }
}
</script>
<style lang="scss" scoped>
.entry {
    height: calc(99vh - 37px);
    background: #ffffff;
    display: flex;
    .content {
        width: calc(100% - 320px);
        min-width: 1050px;
        overflow: auto;
        .content-top {
            height: 420px;
        }
        .content-bottom {
            height: 310px;
            margin-top: 3px;
        }
    }
    
}
.operate {
    .operate-btn {
        width: 98%;
        display: flex;
        justify-content: space-between;
        margin: 10px auto;
    }
}
</style>
